﻿namespace TheCodeWerks.Advertising
{
	using System;
	using System.Collections.Generic;
	using System.Linq;
	using System.Text;
	using System.Windows;
	using AdDuplex;

	public class AdDuplexProvider : IAdvertisingProvider
	{
		public AdvertisingConfiguration Config { get; set; }

		public AdProvider Provider { get { return AdProvider.AdDuplex; } }

		public FrameworkElement CreateControl()
		{
			var control = new AdControl();
			var settings = Config.Providers[Provider];
			var user = Config.User;

			if (Config.TestMode)
			{
				control.IsTest = true;
			}

			control.AppId = settings.Id;

			control.AdLoaded += (source, args) =>
			{
				((AdEvents)((AdControl)source).Tag).AdReady();
			};

			control.AdLoadingError += (source, args) =>
			{
				((AdEvents)((AdControl)source).Tag).NotFilled();
			};

			return control;
		}

		public void ConfigureControl(FrameworkElement element, AdUnit unit)
		{
			var banner = (AdControl)element;
		}

		public void RequestNext(FrameworkElement element)
		{
			var banner = (AdControl)element;
			banner.LoadNewAd();
		}
	}
}
